<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<div class="modal fade" id="add_purchase_request_item_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 940px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增物品</h4>
			</div>
				<div class="box modal-body">
					<form id="searchItemForm" class="form">
					<p>
						<label>申请单号</label>
						<input class="form-control" type="text" name="applicationNo"></input>
						<label>物品代码</label>
						<input class="form-control" type="text" name="itemCode"></input>
						<label>物品名称</label>
						<input class="form-control" type="text" name="itemName"></input>
						<input class="btn btn1" type="button" value="搜索" onclick="initItemTable();" >
					</p>
					</form>
					<table id="add_item_table"></table>
				</div>
			<div class="red" id="add_purchase_request_item_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn2" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<script>

function toAddOrderItem(){
	initItemTable();
	$('#add_purchase_request_item_info').modal('show');
}

var searchData="";

function initItemTable(){
	var columns = [ {
		field : "applicationNo",
		title : "申请单号"
	},{
		field : "itemCode",
		title : "物品代码"
	},{
		field : "chineseName",
		title : "物品名称"
	},{
		field : "brand",
		title : "品牌"
	},{
		field : "categoryName",
		title : "类型"
	},{
		field : "salesUnit",
		title : "单位"
	},{
		field : "number",
		title : "数量"
	},{  
        field: 'operate',  
        title: '操作',  
        width: '80px',  
        events: listMemberOperateEvent,  
        formatter: listMemberOperate  
    }];
	searchData=$("#searchItemForm").serialize();
   	$("#add_item_table").bootstrapTable("destroy");
	$("#add_item_table").bootstrapTable({
   		columns: columns,
   		data: [], 
   		pageSize: 10, 
   		pageList: [10],
   		pagination: true,
		clickToSelect: true,
		uniqueId: "id",
		sidePagination: 'server',
		pageNumber: 1,
		queryParams: function (params) {
			var currentPage=params.offset/params.limit+1;
			var str=searchData+"&currentPage="+currentPage+"&pageSize="+params.limit+"&"+$("#updatePurchaseOrderForm").serialize();
		    return str;
		},
		url: '<%=basePath %>purchaseAgent/listNotAddItem'
   	});
}

function listMemberOperate(value, row, index) {  
    return [  
        '<a class="addItem">添加</button>', 
    ].join('');  
}

window.listMemberOperateEvent = {  
    'click .addItem': function(e, value, row, index) {  
    	addItem(row);
    }
};

function addItem(item){
	addToHasAddTable(item);
	$("#add_item_table").bootstrapTable('remove', {field: 'id', values: [item.id]});
}
</script>